<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
                border: 1px solid black;
            padding: 4px 30px;
            margin-bottom: 4px;
        }
    </style>
</head>

<body>
    <div id="app" class="box">
        <h5>根组件</h5>
        <comp-a></comp-a>
        <comp-b></comp-b>

    </div>
    <!-- 组件A-A -->
    <script type="text/x-template" id="compAa">
            <div class="cbox">
                <h5>组件A-A</h5>
                <p>msg：{{ msg }}</p>
                <input type="button" value="emitMittEvent" @click="emitMittEvent()">
            </div>
        </script>
    <!-- 组件A -->
    <script type="text/x-template" id="compA">
            <div class="cbox">
                <h5>组件A</h5>
                <comp-aa></comp-aa>
            </div>
        </script>

    <!-- 组件B-A -->
    <script type="text/x-template" id="compBa">
            <div class="cbox">
                <h5>组件B-A</h5>
                <p>tempMsg:{{ tempMsg }}</p>
                <input type="button" value="bindMittEvent" @click="bindMittEvent()">
            </div>
        </script>
    <!-- 组件B -->
    <script type="text/x-template" id="compB">
            <div class="cbox">
                <h5>组件B</h5>
                <comp-ba></comp-ba>
            </div>
        </script>

    <script type="module">
        import { createApp } from "../assets/vue3/vue.esm-browser.js";
        import mitt from '../assets/mitt/mitt.mjs'
        let emitter=mitt()
        const CompAa={
            template:'#compAa',
            data(){
                return {
                    msg:'组件a-a的数据变量 msg'
                }
            },
            methods:{
                emitMittEvent(){
                    emitter.emit("updata:msg",this.msg)
                }
            },
            mounted(){
                this.emitMittEvent()
            }
        }
        const CompBa={
            template:'#compBa',
            data(){
                return {
                    tempMsg:''
                }
            },
            methods:{
                    bindMittEvent(){
                        emitter.on("updata:msg",(e)=>{
                            this.tempMsg=e
                        })
                    }
            },
           beforeMount(){
            this.bindMittEvent()
           } 
        }
          const CompA = {
                template: "#compA",
                components: {
                    CompAa,
                }
            }
            const CompB = {
                template: "#compB",
                components: {
                    CompBa,
                },
            }
        createApp({
            data() {
                return {

                }
            },

            components:{
                CompA,CompB
            }
        }).mount("#app");
    </script>
</body>

</html>